// pages/order/order.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navId: '1',//导航的标识
    isTriggered: false,//标识下拉刷新是否触发
    waittingOrderList: [
      {id:"1",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:20,
        time:"16:00"
      },
      {id:"2",
        title:"津G53579 赵女士",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:250,
        time:"12:00"
      },
      {id:"3",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:100,
        time:"13:00"
      },
      {id:"4",
        title:"津G12138 李先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"5",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:500,
        time:"16:00"
      },
      {id:"6",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:150,
        time:"16:00"
      },
      {id:"7",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:208,
        time:"16:00"
      }
    ],//待接订单
    currentOrderList: [
      {id:"8",
        title:"津G53579 孙先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:220,
        time:"18:00"
      },
      {id:"9",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:300,
        time:"16:00"
      },
      {id:"10",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:210,
        time:"16:00"
      },
      {id:"11",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:170,
        time:"16:00"
      },
      {id:"12",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"13",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:120,
        time:"16:00"
      },
      {id:"14",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:110,
        time:"16:00"
      }
    ],//当前订单
    completedOrderList: [
      {id:"15",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"16",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"17",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"18",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"19",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"20",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      },
      {id:"21",
        title:"津G53579 王先生",
        content:" 百事可乐箱装×2 卫生纸×3 ...",
        price:200,
        time:"16:00"
      }
    ]//已完成订单
  },

  // 切换导航
  changeNav(event) {
    let { navId } = this.data
    if (event.target.id == navId) return;
    else {
      this.setData({
        navId: event.target.id
      })
      // console.log(navId)
    }
  },

  //接受订单
  addOrder(event){
    let id = event.target.dataset.id
    let {waittingOrderList,currentOrderList} = this.data
    let index = waittingOrderList.findIndex((item)=>{return item.id== id})
    let orderItem = waittingOrderList.find((item)=>{return item.id== id})
    // console.log(index,orderItem);
    waittingOrderList.splice(index,1)
    currentOrderList.unshift(orderItem)
    this.setData({
      waittingOrderList,
      currentOrderList
    })
  },
  // 拒绝订单
  refuseOrder(event){
    let id = event.target.dataset.id;
    let {waittingOrderList} = this.data;
    let index = waittingOrderList.findIndex((item)=>{return item.id== id});
    waittingOrderList.splice(index,1);
    this.setData({
      waittingOrderList
    })
  },
  // 完成订单
  finsh(event){
    let id = event.target.dataset.id
    let {currentOrderList,completedOrderList} = this.data
    let index = currentOrderList.findIndex((item)=>{return item.id== id})
    let orderItem = currentOrderList.find((item)=>{return item.id== id})
    currentOrderList.splice(index,1)
    completedOrderList.unshift(orderItem)
    this.setData({
      completedOrderList,
      currentOrderList
    })
  },
  // 取消订单
  cancel(event){
    let id = event.target.dataset.id;
    let {currentOrderList} = this.data;
    let index = currentOrderList.findIndex((item)=>{return item.id== id});
    console.log(id,index)
    currentOrderList.splice(index,1);
    this.setData({
      currentOrderList
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})